package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.web.admin.mapper.*;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {

    @Autowired
    ApartmentInfoMapper apartmentInfoMapper;
    @Autowired
    RoomInfoMapper roomInfoMapper;
    @Autowired
    LeaseTermMapper leaseTermMapper;
    @Autowired
    PaymentTypeMapper paymentTypeMapper;

    @Override
    public IPage<AgreementVo> leaseAgreementPage(IPage<AgreementVo> iPage, AgreementQueryVo queryVo) {

        IPage<AgreementVo> agreementVoIPage = baseMapper.selectLeaseAgreementPage(iPage,queryVo);

        return agreementVoIPage;
    }

    @Override
    public AgreementVo getAgreementById(Long agreementId) {

        LeaseAgreement leaseAgreement = baseMapper.selectById(agreementId);
        Long roomId = leaseAgreement.getRoomId();
        Long apartmentId = leaseAgreement.getApartmentId();
        Long leaseTermId = leaseAgreement.getLeaseTermId();
        Long paymentTypeId = leaseAgreement.getPaymentTypeId();
        RoomInfo roomInfo = roomInfoMapper.selectById(roomId);
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(apartmentId);
        LeaseTerm leaseTerm = leaseTermMapper.selectById(leaseTermId);
        PaymentType paymentType = paymentTypeMapper.selectById(paymentTypeId);

        AgreementVo agreementVo = new AgreementVo();
        BeanUtils.copyProperties(leaseAgreement,agreementVo);// 封装租赁合同信息
        agreementVo.setRoomInfo(roomInfo);// 封装房间信息
        agreementVo.setApartmentInfo(apartmentInfo);// 封装公寓信息
        agreementVo.setLeaseTerm(leaseTerm);// 封装租期信息
        agreementVo.setPaymentType(paymentType);// 封装支付方式信息
        return agreementVo;
    }
}




